//
//  PrivacyConfirmDialog.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 18.03.25.
//

import SwiftUI

struct PrivacyConfirmDialog: View {
    
    @State private var isOpenPrivacyView = false
    @State private var isOpenTermsView:Bool = false

    @Binding var isShowPrivacyDialog:Bool
    
    var onConfirmClick:()->Void

    var body: some View {
        VStack {
//            Color.black.opacity(0.3).contentShape(Rectangle()).onTapGesture {
//                isShowPrivacyDialog.toggle()
//            }
            VStack {
                Text("请阅读并同意以下条款")
                    .font(.system(size: 13))
                    .foregroundColor(Color.koiColorTitleSecond)
                    .padding(.top, 30)
                
                HStack (spacing: 1) {
                    Button(action:{
                        isOpenTermsView.toggle()
                    }) {
                        Text("《用户协议》").font(.system(size: 14))
                    }
                    Button(action:{
                        isOpenPrivacyView.toggle()
                    }) {
                        Text("《隐私政策》").font(.system(size: 14))
                    }
                }
                .padding(.top, 10)
                .padding(.bottom, 10)
                Color.koiColorDivider.frame(maxWidth:.infinity, maxHeight: 10)
                Button(action: {
                    onConfirmClick()
                }) {
                    Text("同意并继续")
                        .font(.system(size: 14))
                        .bold()
                        .foregroundColor(Color.koiColorPrimary)
                        .padding(.top, 10)
                        .padding(.bottom, 10)
                }
            }
            .frame(maxWidth: .infinity)
            .padding(.bottom, 20)
            .background(Color.white)
            .clipShape(.rect(topLeadingRadius: 16,topTrailingRadius: 16))
        }
        .fullScreenCover(isPresented: $isOpenPrivacyView, content: {PrivacyWebView.privacyView})
        .fullScreenCover(isPresented: $isOpenTermsView, content: {PrivacyWebView.termsView})
    }
}

@available(iOS 18.0, *)
#Preview {
    @Previewable @State var isShowPrivacyDialog = false
    PrivacyConfirmDialog(isShowPrivacyDialog:$isShowPrivacyDialog, onConfirmClick: {})
}
